//package com.qinghong.blog.config.security;
//
//import com.alibaba.fastjson.JSON;
//import com.qinghong.blog.constant.StatusConst;
//import com.qinghong.blog.entity.UserAuth;
//import com.qinghong.blog.mapper.UserAuthMapper;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.Async;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
///**
// * 登录成功处理
// *
// * @author 11921
// */
//@Component
//public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
//
//    @Autowired
//    private UserAuthMapper userAuthMapper;
//
//
//    @Override
//    public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException {
//        // 更新用户ip，最近登录时间
//        updateUserInfo();
//        UserLoginDTO userLoginDTO = BeanCopyUtil.copyObject(UserUtil.getLoginUser(), UserLoginDTO.class);
//        httpServletResponse.setContentType("application/json;charset=UTF-8");
//        httpServletResponse.getWriter().write(JSON.toJSONString(new Result<UserInfoDTO>(true, StatusConst.OK, "登录成功！", userLoginDTO)));
//    }
//
//    /**
//     * 更新用户信息
//     */
//    @Async
//    public void updateUserInfo() {
//        UserAuth userAuth = UserAuth.builder()
//                .id(UserUtil.getLoginUser().getId())
//                .ipAddr(UserUtil.getLoginUser().getIpAddr())
//                .ipSource(UserUtil.getLoginUser().getIpSource())
//                .lastLoginTime(UserUtil.getLoginUser().getLastLoginTime())
//                .build();
//        userAuthDao.updateById(userAuth);
//    }
//}
